﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditCategory.aspx.cs" Inherits="EditCategories.EditCategory" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link type="text/css" href="Style.css" rel="Stylesheet" />
 </head>
<body>
    <form id="formCategories" runat="server">
    <div>
        <asp:GridView ID="GridCategory" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CategoryID" 
            DataSourceID="LinqDataSourceCategory" onsorting="GridCategory_Sorting"
            PageSize ="5">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" 
                    InsertVisible="False" ReadOnly="True" SortExpression="CategoryID" />
                <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" 
                    SortExpression="CategoryName" />
                <asp:BoundField DataField="Description" HeaderText="Description" 
                    SortExpression="Description" />
            </Columns>
        </asp:GridView>
        <asp:FormView ID="FormCategory" runat="server" AllowPaging="True"  
            DataSourceID="LinqDataSourceCategory" DataKeyNames="CategoryID" 
            oniteminserted="FormCategory_ItemInserted">
             <ItemTemplate>
                <table>
                    <tr>
                        <td>Category name:</td>
                        <td><%# Eval("CategoryName") %></td>
                    </tr>
                    <tr>
                        <td>Description:</td>
                        <td><%# Eval("Description") %></td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Button ID="Button" runat="server" CommandName="New" Text="New category" />
                        </td>
                    </tr>
                </table>
             </ItemTemplate>
             <InsertItemTemplate>
                <table>
                    <tr>
                        <td>Category name:</td>
                        <td>
                            <asp:TextBox ID="TextBoxCategoryName" runat="server" Text='<%# Bind("CategoryName") %>'></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Category desctiption:</td>
                        <td>
                            <asp:TextBox ID="TextBoxCategoryDescription" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Button ID="ButtonInsert" runat="server" CommandName="Insert" Text="Insert" />
                            <asp:Button ID="ButtonCancel" runat="server" CommandName="Cancel" Text="Cancel" />
                        </td>
                    </tr>
                </table>
            </InsertItemTemplate>
        </asp:FormView>

        <div id="ErrorDiv" runat="server" visible="false">
            Cannot sort by Description!
        </div>
        <asp:LinqDataSource ID="LinqDataSourceCategory" runat="server" 
            ContextTypeName="EditCategories.NorthwindDataContext" EntityTypeName="" 
            TableName="Categories" EnableInsert="True">
        </asp:LinqDataSource>
    </div>
    </form>
</body>
</html>
